# -*- coding: utf-8 -*-
from cmsdj.categories.models import Category
from cmsdj.content.models import Content
from django.shortcuts import render_to_response, get_object_or_404
from django.template.context import RequestContext
from cmsdj.util.keywords import get_keywords_text

def list_categories (request):
    categories = Category.get_roots()
    keywords = ""
    for cat in categories:
        keywords = keywords + cat.get_keywords()
    keywords = get_keywords_text(keywords, 10)
    return render_to_response ( 'categories/index.html', locals(), context_instance=RequestContext(request))

def details (request, slug):    
    category = get_object_or_404(Category, slug = slug)
    contents = Content.get_by_category(category)
    return render_to_response ('categories/details.html', locals(), context_instance=RequestContext(request))

def nav (request):
    return render_to_response ('categories/nav_bar.html', context_instance=RequestContext(request))
